package com.medical.medical.service;

import com.medical.medical.entity.Card;
import com.medical.medical.entity.Drug;
import com.medical.medical.mapper.DrugMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class DrugServiceImpl implements DrugService{
    @Resource
    private DrugMapper drugMapper;

    @Override
    public List<Drug> getDrugByRecordId(int recordId) {
        List<Drug> drugList = drugMapper.getDrugByRecordId(recordId);
        return drugList;
    }

    @Override
     /**
      *@author WangLuDong
      *@Description 方法描述 根据药品名称查询药品信息
      *@Date 2022-09-14 23:07:23
       * @param drugName
      *@Return {@link Drug}
      */
    public  List<Drug> getAllDrug(String drugName) {
        return drugMapper.getAllDrug(drugName);
    }

    @Override
     /**
      *@author WangLuDong
      *@Description 方法描述 添加药品
      *@Date 2022-09-14 23:19:24
       * @param drug
      *@Return {@link boolean}
      */
    public boolean addDrug(Drug drug) {
        try {
            return drugMapper.addDrug(drug) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加药品失败");
        }
        return false;
    }

    @Override
    public Card getCard(int pId1) {
        try {
            return drugMapper.getCard(pId1);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("根据id获得当前用户详细信息时发生异常！");
        }
        return null;
    }

    /**
      * @description 修改卡号余额
      * @author ChenLi
      * @date 2022-09-26 16:17:12
      * @param balance1
      * @return {@link boolean}
      */
    @Override
    public boolean editBalance(double balance1) {
        boolean flag = false;
        if (drugMapper.editBalance(balance1)>0){
            flag = true;
        }
        return flag;
    }
}
